// 本地存储token封装
const TOKEN_NAME = 'token'
export const getStorageToken = () => {
  // !记得return出token
  return JSON.parse(localStorage.getItem(TOKEN_NAME)) || {}
}

export const setStorageToken = (payload) => {
  localStorage.setItem(TOKEN_NAME, JSON.stringify(payload))
}

export const removeStorageToken = () => {
  localStorage.removeItem(TOKEN_NAME)
}

// 本地存储频道封装
const CHANNEL_NAME = 'channel'
export const getStorageChannel = () => {
  // !记得return出Channel 不需要设置默认值，如果本地没有数据就会去发请求获取数据
  return JSON.parse(localStorage.getItem(CHANNEL_NAME))
}

export const setStorageChannel = (payload) => {
  localStorage.setItem(CHANNEL_NAME, JSON.stringify(payload))
}

// 本地存储搜索历史记录
const HISTORY_NAME = 'history'
export const getStorageHistory = () => {
  // !记得return出
  return JSON.parse(localStorage.getItem(HISTORY_NAME)) || []
}

export const setStorageHistory = (payload) => {
  localStorage.setItem(HISTORY_NAME, JSON.stringify(payload))
}
